<template>
    <h3 style="text-align: center;">
    购买理财页面
    </h3>
    <table class="table table-bordered" border="1">
        <tr>
            <td>
                理财名称
            </td>
            <td>
                {{Info.F_Fname}}
            </td>
        </tr>
        <tr>
            <td>
                利息
            </td>
            <td>
                <select v-model="Info.F_Uid">
                    <option v-for="item in Xiala" :value=item.F_Uid>{{item.F_ULeach}}</option>
                </select>
            </td>
        </tr>
        <tr>
            <td>
                最低金额
            </td>
            <td>
                {{Info.F_FMinmoney}}
            </td>
        </tr>
        <tr>
            <td>
                风险等级
            </td>
            <td>
                {{Info.F_FFxdj}}
            </td>
        </tr>
        <tr>
            <td>
                理财金额
            </td>
            <td>
                <input type="text"  v-model="GOUmai.FFM_Money">CNY
            </td>
        </tr>
        <tr style="text-align: center;">
            <td colspan="2">
                <button @click="Bunnter">购买</button>
            </td>
        </tr>
    </table>
</template>
<script setup lang="ts">
import { ref } from 'vue';
import { useRoute,useRouter } from 'vue-router';
const route = useRoute();
const router = useRouter();
const Info=ref({
    F_Fid:0,
    F_Fname:'',
    F_FAPY:'',
    F_Uid:0,
    F_FMinmoney:'',
    F_FFxdj:'',
    
})
import {useStore}from '../../store/index.ts'
const store=useStore()

//购买表
const GOUmai=ref({
    FFM_Money:'',
    MyProperty:'',
})
const Xiala=ref([{
    F_Uid:0,
    F_id:0,
    F_ULeach:'',
}])
import { onMounted } from 'vue';
onMounted(() => {
  Binds();  
  Fnewmage();
})
import axios from 'axios';
//绑定下拉框
const Binds=()=>{
    axios.get('https://localhost:44369/api/Financs/Binder')
    .then(res=>{
        Xiala.value=res.data;
    })
    .catch(err=>{
        console.log(err);
    })
}
//反填信息
const Fnewmage=()=>{
    axios.get('https://localhost:44369/api/Financs/FAntianxx',{
        params:{
            F_Fid:route.query.F_Fid
        }
    })
    .then(res=>{
        Info.value=res.data[0];
    })
    .catch(err=>{
        console.log(err);
    })
}
//购买
const Bunnter=()=>{
    // 用户-添加理财金额不能低于最低金额
    if(GOUmai.value.FFM_Money<Info.value.F_FMinmoney){
        alert('用户-添加理财金额不能低于最低金额');
        return;
    }
    axios.post('https://localhost:44369/api/Financs/AddFinamgoumlc',{
        
        F_id:store.F_id,
        F_Fid:route.query.F_Fid,
        FFM_Money:GOUmai.value.FFM_Money,
        MyProperty:GOUmai.value.MyProperty,
    })
    .then(res=>{
        console.log(res);
        if(res.data>0){
           alert("理财成功")
           router
            .push({
                path: "/ShowYonghCherg",
           })
        }else{
            alert("理财失败")
        }
    })
}
</script>